package com.example.vue.comm.domain;

import com.github.pagehelper.Page;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * <h1>PageHelper插件分页对象公共类</h1>
 *
 * @author longdeng
 * @Date 2019/11/14 0014 21:09
 */
@Data
public class PageBean<T> {

    // 当前页
    private Integer currentPage = 1;
    // 每页显示的总条数
    private Integer pageSize = 10;
    // 总条数
    private Long totalNum;
    // 是否有下一页
    private Integer isMore;
    // 总页数
    private Integer totalPage;
    // 开始索引
    private Integer startIndex;
    // 分页结果
    private List<T> items;

    public PageBean() {

    }

    public PageBean(Integer currentPage, Integer pageSize, Integer totalPage) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalPage = pageSize;
    }

    public  PageBean(Page<T> page) {
        this.currentPage = page.getPageNum();
        this.totalPage = page.getPages();
        this.totalNum = page.getTotal();
        items = new ArrayList<>(page.getResult().size());
        items = page.getResult();
        this.pageSize = page.getPageSize();
    }
}
